package com.android.delivery.adapter

import android.widget.TextView
import com.android.delivery.R
import com.android.delivery.activity.OrderSettleActivity
import com.android.delivery.entity.Logistics
import com.android.delivery.util.CopyUtil
import com.android.delivery.util.DateFormatUtil
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder

/**
 * @author: mqwang
 * @create: 3/18/21 1:33 PM
 * @Description:
 */
class JieDanAdapter : BaseQuickAdapter<Logistics, BaseViewHolder>(
        R.layout.adapter_jie_dan) {

    private var type: Int = 0
    private var mListener: OnItemClickListener? = null

    fun setOnItemClickListener(listener: OnItemClickListener) {
        mListener = listener
    }

    override fun convert(helper: BaseViewHolder?, item: Logistics?) {

        helper!!.setText(R.id.tv_order_date, "下单时间：" + DateFormatUtil.formatDate(item!!.createdTime, "yyyy-MM-dd HH:mm:ss"))
        helper!!.setText(R.id.tv_name, item!!.senderName)
        helper!!.setText(R.id.tv_phone, item!!.senderMobile)
        helper!!.setText(R.id.tv_addr, item!!.senderAddress)
        if (type > 0) {
            helper!!.setGone(R.id.tv_zhiding, false)
        } else {
            helper!!.setGone(R.id.tv_zhiding, true)
        }

        if (item.payType == 1) {
            helper.setText(R.id.tv_payType, "寄付")
        } else if (item.payType == 2) {
            helper.setText(R.id.tv_payType, "到付")
        }

        if (item.type == OrderSettleActivity.TYPE_LINDAN_SEND) {
            helper.setText(R.id.tv_mark, "零担")
        } else if (item.type == OrderSettleActivity.TYPE_CITY_SEND) {
            helper.setText(R.id.tv_mark, "同城")
        } else {
            helper.setText(R.id.tv_mark, "速配")
        }

        helper.getView<TextView>(R.id.tv_phone).setOnClickListener {
            CopyUtil.callPhone(mContext, item.senderMobile)
        }

        helper.getView<TextView>(R.id.tv_confirm).setOnClickListener {
            mListener?.onConfirmOrder(item)
        }

        helper.getView<TextView>(R.id.tv_zhiding).setOnClickListener {
            mListener?.onTransferOrder(item)
        }
    }

    open fun setType(type: Int) {
        this.type = type;
    }

    interface OnItemClickListener {
        fun onConfirmOrder(logistics: Logistics)
        fun onTransferOrder(logistics: Logistics)
    }
}